import { initSdk } from '../config'
import { PublicKey } from '@solana/web3.js'

export const getPUMPPrice = async () => {
  const raydium = await initSdk()
  
  // PUMP代币地址
  const currentMint = new PublicKey('9DHe3pycTuymFk4H4bbPoAJ4hQrr2kaLDF6J6aAKpump')
  // USDC代币地址
  const USDC_MINT = new PublicKey('So11111111111111111111111111111111111111112')

  try {
    // 获取代币信息
    const pumpTokenInfo = await raydium.token.getTokenInfo(currentMint.toBase58())
    console.log('PUMP代币信息:', {
      symbol: pumpTokenInfo.symbol,
      decimals: pumpTokenInfo.decimals,
      name: pumpTokenInfo.name
    })

    // 获取包含PUMP的池子列表
    const pools = await raydium.api.fetchPoolByMints({
      mint1: currentMint.toBase58(),
    //   mint2: USDC_MINT.toBase58(),
      sort: 'liquidity',
      order: 'desc'
    })
    console.log('所有池子',pools)
    if (pools && pools.data && pools.data.length > 0) {
      const bestPool = pools.data[0]
      console.log('找到最佳流动性池:', {
        poolId: bestPool.id,
        price: bestPool.price
      })
    } else {
      console.log('未找到包含PUMP代币的流动性池')
    }

  } catch (error) {
    console.error('查询价格时出错:', error)
  }
}

// 执行查询
getPUMPPrice() 